#include <stdio.h>

struct node
{
    int data;
    struct node *pnext;
};

void travList(struct node*, void (*)(const struct node *));
void outputNode(const struct node*);

int main(void)
{
    struct node a1, a2, a3, a4, a5, a6;

    struct node *pHead = &a1;
    struct node a7 = {7, NULL};

    printf("creating...\n");

    a1.data = 1;
    a1.pnext = &a2;
    a2.data = 2;
    a2.pnext = &a3;
    a3.data = 3;
    a3.pnext = &a4;
    a4.data = 4;
    a4.pnext = &a5;
    a5.data = 5;
    a5.pnext = &a6;
    a6.data = 6;
    a6.pnext = &a7;

    travList(pHead, outputNode);

    printf("\n");

    return 0;
}

void travList(struct node *pHead, void (*pf)(const struct node *))
{
    struct node *p = pHead;

    while (p != NULL)
    {
        pf(p);
        p = p->pnext;
    }
}

void outputNode(const struct node *pNode)
{
    printf("%d ", pNode->data);
}


